# -*- coding: utf-8 -*-

from datetime import timedelta
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dwd.tab.dwd_tab_barscan_other_base_dt import jms_dwd__dwd_tab_barscan_other_base_dt
from jms.dwd.dwd_warhouse.dwd_wide_unsign_trace_waybill_step_dt import jms_dwd__dwd_wide_unsign_trace_waybill_step_dt
from jms.dim.dim_network_whole_massage import jms_dim__dim_network_whole_massage
from jms.dim.dim_ep_flow_direction_base import jms_dim__dim_ep_flow_direction_base
from jms.dim.dim_ep_center_person_base import jms_dim__dim_ep_center_person_base
from jms.dm.dm_tab_scan_piece_detail_dt import jms_dm__dm_tab_scan_piece_detail_dt
from jms.time_sensor.time_after_05_45 import time_after_05_45

jms_dm__dm_tab_scan_unpacking_detail_dt = SparkSqlOperator(
    task_id='jms_dm__dm_tab_scan_unpacking_detail_dt',
    conn_id='spark_route',
    email=['jokic.wang@jtexpress.com', 'yl_bigdata@yl-scm.com'],
    name='jms_dm__dm_tab_scan_unpacking_detail_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dm/dm_tab_scan_unpacking_detail_dt/execute.sql',
    # sla=timedelta(hours=7),
    driver_memory='4G',
    driver_cores=1,
    executor_memory='6G',
    executor_cores=5,
    num_executors=32,
    pool_slots=2,
    execution_timeout=timedelta(minutes=40),
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 36,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 600,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.shuffle.partitions': 540,
          'spark.shuffle.file.buffer': '64k',
          'spark.executor.extraJavaOptions': '-XX:+UseG1GC -XX:ParallelGCThreads=5'
          },
    hiveconf={'hive.exec.dynamic.partition': 'true',
              'hive.exec.dynamic.partition.mode': 'nonstrict',
              'hive.exec.max.dynamic.partitions.pernode': 200,
              'hive.exec.max.dynamic.partitions': 200,
              },
    yarn_queue='pro',
)

jms_dm__dm_tab_scan_unpacking_detail_dt << [
    jms_dwd__dwd_tab_barscan_other_base_dt,
    jms_dwd__dwd_wide_unsign_trace_waybill_step_dt,
    jms_dim__dim_network_whole_massage,
    jms_dim__dim_ep_flow_direction_base,
    jms_dim__dim_ep_center_person_base,
    jms_dm__dm_tab_scan_piece_detail_dt,
    time_after_05_45
]
